package com.hlpedu.service.impl;

import com.hlpedu.factory.BeanFactory;
import com.hlpedu.service.EmpService;
import com.hlpedu.mapper.EmpMapper;
import com.hlpedu.mapper.impl.EmpMapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * 业务层接口实现类
 */
@Service
   // @Component
public class EmpServiceImpl implements EmpService {
    //private EmpMapper empMapper=new EmpMapperImpl ();
    //通过工厂创建bean对象
    //EmpMapper empMapper=(EmpMapper) BeanFactory
      //      .getBean("empMapper");
    @Autowired
    private EmpMapper empMapper;
    @Override
    public void saveEmp() {
        System.out.println("调用mapper层的addEmp()方法执行新增业务。。。");
        //通过ioc获取bean对象
        //1.启动容器
        //ApplicationContext ac =
                new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取bean对象
        //2.1 通过class，获取bean实例
        //EmpMapper empMapper=ac.getBean(EmpMapper.class);
        empMapper.addEmp();
    }
}
